package harima.collision.bodies;

import java.awt.geom.Line2D;


public class PlatformBody extends Body{

	
	public PlatformBody(float w,float h)
	{
		super(w, h);
		movementSpeed  = 1f;
		collisionOffset = 1f;
	}
		
	public PlatformBody(float w, float h, float speed)
	{
		super(w, h);
		movementSpeed = speed;
		collisionOffset = 1f;
	}
	
	
	protected float movementSpeed;
	protected float getMovementSpeed(){return movementSpeed;}
	
	protected Direction movementDirection;
	public Direction getMovementDirection(){return movementDirection;}
	public void setMovementDirection(Direction _direction){movementDirection = _direction;}
	
	protected float collisionOffset;
	public void setCollisionOffset(float _collisionOffset){ collisionOffset = _collisionOffset;}
	public float getCollisionOffset(){return collisionOffset;}

	
	public void moveSelft()
	{
		moveBody(this);
	}
	
	public void moveBodiesAbove()
	{
		
		Line2D.Float above = computeCollisionSide();
		
		for(Body body : getContext().getBodies())
		{
			if(body != this && body.intersectsLine(above) )
			{
				moveBody(body);
			}
		}
		
		
	}
	
	private Line2D.Float computeCollisionSide() {
		Line2D.Float above = Direction.Up.getSide(this);
		moveLine(Direction.Up, collisionOffset, above);
		return above;
	}
	
	private void moveBody(Body body)
	{
		if(movementDirection != null && body.canMove(movementDirection, movementSpeed))
		{
			body.move(movementDirection, movementSpeed);
		}
	}
}
